package cn.buk.qms.web;

import cn.buk.common.JsonResult;
import cn.buk.common.dto.CommonDto;
import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.flight.dto.KeyCustomerPolicyDto;
import cn.buk.tms.flight.service.FlightKeyCustomerPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 机票私有政策
 * @author yfdai
 */
@RestController
public class FlightKeyCustomerPolicyController extends BaseController {

  @Autowired
  public FlightKeyCustomerPolicyController(FlightKeyCustomerPolicyService keyCustomerPolicyService) {
    this.keyCustomerPolicyService = keyCustomerPolicyService;
  }

  private final FlightKeyCustomerPolicyService keyCustomerPolicyService;

  /**
   * 保存机票大客户政策信息
   */
  @PostMapping(value = "/flight/keyCustomerPolicy")
  public JsonResult saveKeyCustomerPolicy(HttpServletRequest request,
                                     @ModelAttribute KeyCustomerPolicyDto dto) {
    return keyCustomerPolicyService.saveKeyCustomerPolicy(getEnterpriseId(request), dto);
  }

  /**
   * 查找机票大客户政策信息
   */
  @RequestMapping("/flight/keyCustomerPolicies")
  public CommonDto<KeyCustomerPolicyDto> searchKeyCustomerPolicies(HttpServletRequest request,
                                                        @ModelAttribute("sc") CommonSearchCriteria sc) {
    List<KeyCustomerPolicyDto> infos = keyCustomerPolicyService.searchKeyCustomerPolicies(getEnterpriseId(request), sc);

    CommonDto<KeyCustomerPolicyDto> dto = new CommonDto<>();
    dto.setDataList(infos);
    dto.setPage(sc.getPage());

    return dto;
  }

}
